// pages/order/order.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        deltips:false,//删除提示
        orderLists:null,//订单列表
        index:0  //全部显示
    },
     // 修改tabs下标方法
     setIndex(options){
        let index = options.target.dataset.index;
        this.setData({
            index
        })
    },
    // 删除订单
    delOrder(data){
        let id = data.currentTarget.dataset.id;
        let index = this.data.orderLists.findIndex(item=>item.orderId == id);
        this.data.orderLists.splice(index,1);
        wx.setStorageSync("orderLists",this.data.orderLists)
        this.setData({
            orderLists:wx.getStorageSync('orderLists'),
            deltips:true,
        })
        // 关闭提示
        setTimeout(() => {
            this.setData({
              deltips:false,
            })
          }, 1500);
    },
    // 点击已发货按钮
    setType2(data){
        let id = data.currentTarget.dataset.id;
        let index = this.data.orderLists.findIndex(item=>item.orderId == id);
        this.data.orderLists[index].type = 3;
        wx.setStorageSync("orderLists",this.data.orderLists)
        let type = "orderLists["+index+"].type"
        this.setData({
            [type]:3
        })
    },
    // 点击确认收货按钮
    setType3(data){
        let id = data.currentTarget.dataset.id;
        let index = this.data.orderLists.findIndex(item=>item.orderId == id);
        this.data.orderLists[index].type = 4;
        wx.setStorageSync("orderLists",this.data.orderLists)
        let type = "orderLists["+index+"].type"
        this.setData({
            [type]:4
        })
    },
    // 点击立即付款按钮
    setType1(data){
        let id = data.currentTarget.dataset.id;
        let index = this.data.orderLists.findIndex(item=>item.orderId == id);
        this.data.orderLists[index].type = 2;
        wx.setStorageSync("orderLists",this.data.orderLists)
        let type = "orderLists["+index+"].type"
        this.setData({
            [type]:2
        })
    },
    // 点击立即评价
    setType4(data){
        let id = data.currentTarget.dataset.id;
        let index = this.data.orderLists.findIndex(item=>item.orderId == id);
        this.data.orderLists[index].type = 5;
        wx.setStorageSync("orderLists",this.data.orderLists)
        let type = "orderLists["+index+"].type"
        this.setData({
            [type]:5
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let orderLists = wx.getStorageSync("orderLists");
        this.setData({
            orderLists
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        wx.reLaunch({
          url: '/pages/my/my',
        })
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})